<template>
	<view class="pages">
		<view class="userInfo" @click.capture="toUserInfo">
			<cloud-image width="150rpx" height="150rpx" v-if="userInfo.avatar_file&&userInfo.avatar_file.url" :src="userInfo.avatar_file.url"></cloud-image>
			<image v-else class="logo-img" src="@/static/uni-center/defaultAvatarUrl.png"></image>
			<view class="logo-title">
				<text class="uer-name" v-if="hasLogin">{{userInfo.nickname||userInfo.username||userInfo.mobile}}</text>
				<text class="uer-name" v-else>{{$t('mine.notLogged')}}</text>
			</view>
		</view>
		<view class="card">
			<view v-for="(item,index) in myidle" :key="index">
				<u-card :title="item.title "  :thumb="item.url" thumb-width="120">
					<view  slot="body">
						<view class="u-body-item u-flex u-border-bottom u-col-between u-p-t-0">
							<view class="u-body-item-title u-line-2">
								{{item.content}}
								<view class="total">
									￥{{item.total}}
								</view>
							</view>
						</view>
					</view>
					<view class="" slot="foot" >
						<u-button size="mini" @click="showmodal(item._id)">下架</u-button>
					</view>
				</u-card>
				
			</view>
		</view>
			
				<u-modal v-model="show" :content="content" show-cancel-button="true"  @confirm="delect()"></u-modal>
				
			
	</view>
</template>

<script>
	import {
		mapGetters,
		
	} from 'vuex';
	export default{
		onLoad() {
			this.getmyidle()
		},
		data(){
			return{
				content: '确定要下架吗？',
				myidle:[],
				show: false,
				id:'',
			}
		},
		computed: {
			...mapGetters({
				userInfo: 'user/info',
				hasLogin: 'user/hasLogin'
			})
			// #ifdef APP-PLUS
			,
			appVersion() {
				return getApp().appVersion
			}
			// #endif
			,
			appConfig() {
				return getApp().globalData.config
			},
			
		},
		methods:{
			
			toUserInfo() {
				uni.navigateTo({
					url: '/pages/ucenter/userinfo/userinfo'
				})
				
			},
			getmyidle(){
				const db = uniCloud.database() //代码块为cdb
				// 使用uni-clientDB
				db.collection('opendb-news-articles')
				  .where({
				   user_id:this.$store.state.user.info._id
				  }).get()
				  .then((res)=>{
				     this.myidle=res.result.data
						
				  }).catch((err)=>{
				    console.log(err.code); // 打印错误码
				        console.log(err.message); // 打印错误内容
				  }) 
			},
			delect(){
				
				const db = uniCloud.database();
				 db.collection("opendb-news-articles").doc(this.id).remove()
				this.getmyidle()
				
			},
			showmodal(_id){
				this.show=true;
				this.id=_id;
				console.log(this.id)
			}
			
		}
		
	}
</script>

<style lang="scss">
	.pages{
		background-color: #000000;
	}
	.userInfo {
		width: 750rpx;
		padding: 20rpx;
		padding-top: 50px;
		background-image: url(../../static/uni-center/headers.png);
		flex-direction: column;
		align-items: center;
	}	
	.logo-img {
		width: 150rpx;
		height: 150rpx;
		border-radius: 150rpx;
	}
	.uer-name {
		height: 100rpx;
		line-height: 100rpx;
		font-size: 38rpx;
		color: #FFFFFF;
	}
	.u-card-wrap { 
			background-color: $u-bg-color;
			padding: 1px;
			
		}
		
		.u-body-item {
			font-size: 32rpx;
			color: #333;
			padding: 20rpx 10rpx;
		}
			
		.u-body-item image {
			width: 120rpx;
			flex: 0 0 120rpx;
			height: 120rpx;
			border-radius: 8rpx;
			margin-left: 12rpx;
		}
	
	.total{
		color: red;
		
		
	}
	
</style>
